class Solution(object):
    def addStrings(self, num1, num2):
        """
        :type num1: str
        :type num2: str
        :rtype: str
        """
        t = []
        s = ''
        res = ''
        zs = []
        if len(num1) < len(num2):
            for i in range(1, len(num1)+1):
                t.append((int(num1[-i])+int(num2[-i])))
            for i in range(len(num2)-len(num1)):
                zs.append(int(num2[i]))
            for i in range(1,len(zs)+1):
                t.append(zs[-i])
        else:
            for i in range(1, len(num2)+1):
                t.append((int(num1[-i])+int(num2[-i])))
            for i in range(len(num1)-len(num2)):
                zs.append(int(num1[i]))
            for i in range(1, len(zs)+1):
                t.append(zs[-i])
        t.append(0)
        for i in range(len(t)):
            if t[i] >= 10:
                s += str(t[i]%10)
                t[i+1] += 1
            else:
                s += str(t[i])
        if s[-1] == '0':
            for i in range(len(s)-1):
                res += s[i]
            return res[::-1]
        else:
            return s[::-1]



t = Solution()
res = t.addStrings('4018','5')
print(res)
